package com.zzsy.carosshopprojects.util.sunmiprint;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.base.BaseApplation;
import com.zzsy.carosshopprojects.base.ConfigureFile;
import com.zzsy.carosshopprojects.base.DoHandoverCzBean;
import com.zzsy.carosshopprojects.bean.CarCardBean;
import com.zzsy.carosshopprojects.bean.ChangeShiftsBean;
import com.zzsy.carosshopprojects.bean.DoHandoverBean;
import com.zzsy.carosshopprojects.bean.OrderDetialBean;
import com.zzsy.carosshopprojects.util.ConverterHelper;
import com.zzsy.carosshopprojects.util.DataUtil;
import com.zzsy.carosshopprojects.util.FormatTimeUtil;
import com.zzsy.carosshopprojects.util.SPUtil;
import com.zzsy.carosshopprojects.util.StringUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class PrintHelper {
    private static PrintHelper printHelper;
    private static final boolean isBold = true;//设置打印小票是否加粗
    private static final int TextSize = 24;//设置打印小票字体大小

    public static synchronized PrintHelper getInstance() {
        if (printHelper == null) {
            printHelper = new PrintHelper();
        }
        return printHelper;
    }

    /**
     * 打印加油员交接班历史记录小票
     */
    public void printChangeShiftsStaff(ChangeShiftsBean.ListBean listBean) {
        //支付宝
        String aliPayAmount = listBean.getAliPayAmount();
        if (StringUtils.isEmpty(aliPayAmount)) {
            // 小程序金额
            aliPayAmount = "0";
        }
        double aliPayAmountStr = ConverterHelper.toBigDecimal(aliPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //实总金额
        String amount = listBean.getAmount();
        if (StringUtils.isEmpty(amount)) {
            // 支付宝处理结果
            amount = "0";
        }
        double amountStr = ConverterHelper.toBigDecimal(amount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //订单金额
        String orderAmount = listBean.getOrderAmount();
        if (StringUtils.isEmpty(orderAmount)) {
            orderAmount = "0";
        }
        double orderAmountStr = ConverterHelper.toBigDecimal(orderAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //银联
        String unionPayAmount = listBean.getUnionPayAmount();
        if (StringUtils.isEmpty(unionPayAmount)) {
            unionPayAmount = "0";
        }
        double unionPayAmountStr = ConverterHelper.toBigDecimal(unionPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //会员卡
        String balanceAmount = listBean.getBalanceAmount();
        if (StringUtils.isEmpty(balanceAmount)) {
            balanceAmount = "0";
        }
        double balanceAmountStr = ConverterHelper.toBigDecimal(balanceAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //微信
        String weixinPayAmount = listBean.getWeixinPayAmount();
        if (StringUtils.isEmpty(weixinPayAmount)) {
            weixinPayAmount = "0";
        }
        double weixinPayAmountStr = ConverterHelper.toBigDecimal(weixinPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //时间
        String dataTime = listBean.getEndTime();
        String startTime = listBean.getStartTime();
        if (!StringUtils.isEmpty(dataTime)) {
            dataTime = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(dataTime) / 1000), "yyyy-MM-dd HH:mm:ss");

        }
        if (!StringUtils.isEmpty(startTime)) {
            startTime = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(startTime) / 1000), "yyyy-MM-dd HH:mm:ss");

        }
        //订单总数
        String orderCount = listBean.getOrderCount();
        if (StringUtils.isEmpty(orderCount)) {
            orderCount = "0";
        }

        //设备名称
        String terminalName = listBean.getTerminalName();
        if (StringUtils.isEmpty(terminalName)) {
            terminalName = "";
        }
        //设备名称
        String storeName = listBean.getStoreName();
        if (StringUtils.isEmpty(storeName)) {
            storeName = "";
        }
        //优惠券金额
        String couponAmount = listBean.getCouponAmount();
        if (StringUtils.isEmpty(couponAmount)) {
            couponAmount = "0";
        }
        double couponAmountStr = ConverterHelper.toBigDecimal(couponAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        //折扣金额
        String rebateAmount = listBean.getRebateAmount();
        if (StringUtils.isEmpty(rebateAmount)) {
            rebateAmount = "0";
        }
        double rebateAmountStr = ConverterHelper.toBigDecimal(rebateAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        //直降金额
        String downAmount = listBean.getDownAmount();
        if (StringUtils.isEmpty(downAmount)) {
            downAmount = "0";
        }
        double downAmountStr = ConverterHelper.toBigDecimal(downAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        //红包金额
        String redPackedAmount = listBean.getRedPackedAmount();
        if (StringUtils.isEmpty(redPackedAmount)) {
            redPackedAmount = "0";
        }
        double redPackedAmountStr = ConverterHelper.toBigDecimal(redPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        String serviceCardCount = listBean.getServiceCardNumber();
        if (StringUtils.isEmpty(serviceCardCount)) {
            serviceCardCount = "0";
        }
        String content = "交接班(车油服)(重打印)\n" + "***********欢迎光临***********\n\n"
                + "门店名称：" + storeName + "\n"
                + "设备名称：" + terminalName + "\n"
                + "开始时间：" + startTime + "\n"
                + "结束时间：" + dataTime + "\n"
                + "订单总额：" + orderAmountStr + "\n"
                + "实收总额：" + amountStr + "\n"
                + "支付宝：" + aliPayAmountStr + "\n"
                + "微信：" + weixinPayAmountStr + "\n"
                + "银联：" + unionPayAmountStr + "\n"
                + "会员卡：" + balanceAmountStr + "\n"
                + "总订单数：" + orderCount + "\n"
                + "优惠券金额：" + couponAmountStr + "\n"
                + "折扣金额 ：" + rebateAmountStr + "\n"
                + "直降金额：" + downAmountStr + "\n"
                + "红包金额：" + redPackedAmountStr + "\n"
                + "服务卡发放次数：" + serviceCardCount + "\n"
                + "------------------------------\n\n" +
                "本页由【车油服智慧有限公司】打印\n\n";
        SunmiPrintHelper.getInstance().printText(content, TextSize, isBold, false);
        SunmiPrintHelper.getInstance().feedPaper();
    }

    /**
     * 打印吧台交接班历史记录小票
     *
     * @param listBean
     */
    public void printChangeShiftsBar(ChangeShiftsBean.ListBean listBean) {
        //支付宝
        String aliPayAmount = listBean.getAliPayAmount();
        //c充值金额
        String amount = listBean.getAmount();
        //银联
        String unionPayAmount = listBean.getUnionPayAmount();
        //交接班时间
        String dataTime = listBean.getEndTime();
        //上次交接班时间
        String startTime = listBean.getStartTime();

        if (!StringUtils.isEmpty(dataTime)) {
            dataTime = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(dataTime) / 1000), "yyyy-MM-dd HH:mm:ss");

        }
        if (!StringUtils.isEmpty(startTime)) {
            startTime = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(startTime) / 1000), "yyyy-MM-dd HH:mm:ss");

        }

        //现金
        String cashAmount = listBean.getCashAmount();
        //订单总数
        String orderCount = listBean.getTotalOrder();
        //微信
        String weixinPayAmount = listBean.getWeixinPayAmount();

        String redPackedAllAmount = listBean.getRedPackedAllAmount();
        if (StringUtils.isEmpty(redPackedAllAmount)) {
            redPackedAllAmount = "0";
        }
        redPackedAllAmount = ConverterHelper.toBigDecimal(redPackedAllAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String qyRedPackedAmount = listBean.getQyRedPackedAmount();
        if (StringUtils.isEmpty(qyRedPackedAmount)) {
            qyRedPackedAmount = "0";
        }
        qyRedPackedAmount = ConverterHelper.toBigDecimal(qyRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String cyRedPackedAmount = listBean.getCyRedPackedAmount();
        if (StringUtils.isEmpty(cyRedPackedAmount)) {
            cyRedPackedAmount = "0";
        }
        cyRedPackedAmount = ConverterHelper.toBigDecimal(cyRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String lngRedPackedAmount = listBean.getLngRedPackedAmount();
        if (StringUtils.isEmpty(lngRedPackedAmount)) {
            lngRedPackedAmount = "0";
        }
        lngRedPackedAmount = ConverterHelper.toBigDecimal(lngRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String cngRedPackedAmount = listBean.getCngRedPackedAmount();
        if (StringUtils.isEmpty(cngRedPackedAmount)) {
            cngRedPackedAmount = "0";
        }
        cngRedPackedAmount = ConverterHelper.toBigDecimal(cngRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String sendRedPackedAmount = listBean.getSendRedPackedAmount();
        if (StringUtils.isEmpty(sendRedPackedAmount)) {
            sendRedPackedAmount = "0";
        }
        sendRedPackedAmount = ConverterHelper.toBigDecimal(sendRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";


        //小程序额度
        String xcxAmount = listBean.getXcxAmount();
        //pos额度
        String posAmount = listBean.getPosAmount();


        if (StringUtils.isEmpty(xcxAmount)) {
            // 小程序金额
            xcxAmount = "0";
        }
        double xcxAmountStr = ConverterHelper.toBigDecimal(xcxAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        if (StringUtils.isEmpty(posAmount)) {
            // 支付宝处理结果
            posAmount = "0";
        }
        double posAmountStr = ConverterHelper.toBigDecimal(posAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        // 支付宝处理结果
        if (StringUtils.isEmpty(aliPayAmount)) {
            aliPayAmount = "0";
        }
        double aliPayAmountStr = ConverterHelper.toBigDecimal(aliPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        // 充值总额处理结果
        if (StringUtils.isEmpty(amount)) {
            amount = "0";
        }
        double amountStr = ConverterHelper.toBigDecimal(amount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //银联处理结果
        if (StringUtils.isEmpty(unionPayAmount)) {
            unionPayAmount = "0";
        }
        double unionPayAmountStr = ConverterHelper.toBigDecimal(unionPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //微信处理结果
        if (StringUtils.isEmpty(weixinPayAmount)) {
            weixinPayAmount = "0";
        }
        double weixinPayAmountStr = ConverterHelper.toBigDecimal(weixinPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //余额处理结果
        if (StringUtils.isEmpty(cashAmount)) {
            cashAmount = "0";
        }
        double cashAmountStr = ConverterHelper.toBigDecimal(cashAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //设备名称
        String terminalName = listBean.getTerminalName();
        if (StringUtils.isEmpty(terminalName)) {
            terminalName = "";
        }
        //设备名称
        String storeName = listBean.getStoreName();
        if (StringUtils.isEmpty(storeName)) {
            storeName = "";
        }
        String content = "交接班(车油服)(重打印)\n" + "***********欢迎光临***********\n\n"
                + "门店名称：" + storeName + "\n"
                + "设备名称：" + terminalName + "\n"
                + "开始时间：" + startTime + "\n"
                + "结束时间：" + dataTime + "\n\n"
                + "充值总额：" + amountStr + "\n"
                + "支付宝：" + aliPayAmountStr + "\n"
                + "微信：" + weixinPayAmountStr + "\n"
                + "银联：" + unionPayAmountStr + "\n"
                + "现金：" + cashAmountStr + "\n"
                + "总订单数：" + orderCount + "\n"
                + "小程序总额：" + xcxAmountStr + "\n"
                + "pos总额：" + posAmountStr + "\n"
                + "红包总金额：" + redPackedAllAmount + "\n"
                + "汽油红包：" + qyRedPackedAmount + "\n"
                + "柴油红包：" + cyRedPackedAmount + "\n"
                + "LNG红包：" + lngRedPackedAmount + "\n"
                + "CNG红包：" + cngRedPackedAmount + "\n"
                + "补发红包：" + sendRedPackedAmount + "\n"
                + "------------------------------\n\n" +
                "本页由【车油服智慧有限公司】打印\n\n";
        SunmiPrintHelper.getInstance().printText(content, TextSize, isBold, false);
        SunmiPrintHelper.getInstance().feedPaper();
    }

    /**
     * 打印操作员交接班小票
     *
     * @param bean
     */
    public void printDoHandover(DoHandoverCzBean bean) {
        if (!SPUtil.getInstance().getString(ConfigureFile.CHANGESHIFESTICKET, "").equals("1")) {
            return;
        }
        //支付宝
        String aliPayAmount = bean.getAliPayAmount();
        if (StringUtils.isEmpty(aliPayAmount)) {
            // 小程序金额
            aliPayAmount = "0";
        }
        double aliPayAmountStr = ConverterHelper.toBigDecimal(aliPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //实总金额
        String amount = bean.getAmount();
        if (StringUtils.isEmpty(amount)) {
            // 支付宝处理结果
            amount = "0";
        }
        double amountStr = ConverterHelper.toBigDecimal(amount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //订单金额
        String orderAmount = bean.getOrderAmount();
        if (StringUtils.isEmpty(orderAmount)) {
            orderAmount = "0";
        }
        double orderAmountStr = ConverterHelper.toBigDecimal(orderAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //银联
        String unionPayAmount = bean.getUnionPayAmount();
        if (StringUtils.isEmpty(unionPayAmount)) {
            unionPayAmount = "0";
        }
        double unionPayAmountStr = ConverterHelper.toBigDecimal(unionPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //会员卡
        String balanceAmount = bean.getBalanceAmount();
        if (StringUtils.isEmpty(balanceAmount)) {
            balanceAmount = "0";
        }
        double balanceAmountStr = ConverterHelper.toBigDecimal(balanceAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //微信
        String weixinPayAmount = bean.getWeixinPayAmount();
        if (StringUtils.isEmpty(weixinPayAmount)) {
            weixinPayAmount = "0";
        }
        double weixinPayAmountStr = ConverterHelper.toBigDecimal(weixinPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //时间
        String dataTime = bean.getDateTime();
        String startTime = bean.getStartTime();
        if (StringUtils.isEmpty(dataTime)) {
            dataTime = "";
        }
        if (StringUtils.isEmpty(startTime)) {
            startTime = "";
        }
        //订单总数
        String orderCount = bean.getOrderCount();
        if (StringUtils.isEmpty(orderCount)) {
            orderCount = "0";
        }
        //服务卡数量
        String washCardCount = "";
        if (StringUtils.isEmpty(washCardCount)) {
            washCardCount = "0";
        }

        //优惠券金额
        String couponAmount = bean.getCouponAmount();
        if (StringUtils.isEmpty(couponAmount)) {
            couponAmount = "0";
        }
        double couponAmountStr = ConverterHelper.toBigDecimal(couponAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        //折扣金额
        String rebateAmount = bean.getRebateAmount();
        if (StringUtils.isEmpty(rebateAmount)) {
            rebateAmount = "0";
        }
        double rebateAmountStr = ConverterHelper.toBigDecimal(rebateAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        //直降金额
        String downAmount = bean.getDownAmount();
        if (StringUtils.isEmpty(downAmount)) {
            downAmount = "0";
        }
        double downAmountStr = ConverterHelper.toBigDecimal(downAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        //红包金额
        String redPackedAmount = bean.getRedPackedAmount();
        if (StringUtils.isEmpty(redPackedAmount)) {
            redPackedAmount = "0";
        }
        double redPackedAmountStr = ConverterHelper.toBigDecimal(redPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        String serviceCardCount = bean.getServiceCardCount();
        if (StringUtils.isEmpty(serviceCardCount)) {
            serviceCardCount = "0";
        }
        String storeName = DataUtil.getInstance().getStoreName();
        String terminalName = bean.getTerminalName() + "";
        String content = "交接班(车油服)\n" + "***********欢迎光临***********\n\n"
                + "门店名称：" + storeName + "\n"
                + "设备名称：" + terminalName + "\n"
                + "开始时间：" + startTime + "\n"
                + "结束时间：" + dataTime + "\n"
                + "订单总额：" + orderAmountStr + "\n"
                + "实收总额：" + amountStr + "\n"
                + "支付宝：" + aliPayAmountStr + "\n"
                + "微信：" + weixinPayAmountStr + "\n"
                + "银联：" + unionPayAmountStr + "\n"
                + "会员卡：" + balanceAmountStr + "\n"
                + "总订单数：" + orderCount + "\n"
                + "优惠券金额：" + couponAmountStr + "\n"
                + "折扣金额 ：" + rebateAmountStr + "\n"
                + "直降金额：" + downAmountStr + "\n"
                + "红包金额：" + redPackedAmountStr + "\n"
                + "服务卡发放次数：" + serviceCardCount + "\n"
                + "------------------------------\n\n" +
                "本页由【车油服智慧有限公司】打印\n\n";
        SunmiPrintHelper.getInstance().printText(content, TextSize, isBold, false);
        SunmiPrintHelper.getInstance().feedPaper();
    }

    /**
     * 打印吧台交接班小票
     *
     * @param bean
     */
    public void printDoRechargeHandover(DoHandoverBean bean) {
        if (!SPUtil.getInstance().getString(ConfigureFile.CHANGESHIFESTICKET, "").equals("1")) {
            return;
        }
        //支付宝
        String aliPayAmount = bean.getAliPayAmount();
        //c充值金额
        String amount = bean.getAmount();
        //银联
        String unionPayAmount = bean.getUnionPayAmount();
        //交接班时间
        String dataTime = bean.getDataTime();
        //上次交接班时间
        String startTime = bean.getStartTime();

        if (StringUtils.isEmpty(dataTime)) {
            dataTime = "";
        }
        if (StringUtils.isEmpty(startTime)) {
            startTime = "";
        }

        //现金
        String cashAmount = bean.getCashAmount();
        //订单总数
        String orderCount = String.valueOf(bean.getOrderCount());
        //微信
        String weixinPayAmount = bean.getWeixinPayAmount();

        //小程序额度
        String xcxAmount = bean.getXcxAmount();
        //pos额度
        String posAmount = bean.getPosAmount();
        //会员优惠券总额度
        String memberCouponAmountSum = bean.getMemberCouponAmountSum();

        String redPackedAllAmount = bean.getRedPackedAllAmount();
        if (StringUtils.isEmpty(redPackedAllAmount)) {
            redPackedAllAmount = "0";
        }
        redPackedAllAmount = ConverterHelper.toBigDecimal(redPackedAllAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String qyRedPackedAmount = bean.getQyRedPackedAmount();
        if (StringUtils.isEmpty(qyRedPackedAmount)) {
            qyRedPackedAmount = "0";
        }
        qyRedPackedAmount = ConverterHelper.toBigDecimal(qyRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String cyRedPackedAmount = bean.getCyRedPackedAmount();
        if (StringUtils.isEmpty(cyRedPackedAmount)) {
            cyRedPackedAmount = "0";
        }
        cyRedPackedAmount = ConverterHelper.toBigDecimal(cyRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String lngRedPackedAmount = bean.getLngRedPackedAmount();
        if (StringUtils.isEmpty(lngRedPackedAmount)) {
            lngRedPackedAmount = "0";
        }
        lngRedPackedAmount = ConverterHelper.toBigDecimal(lngRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String cngRedPackedAmount = bean.getCngRedPackedAmount();
        if (StringUtils.isEmpty(cngRedPackedAmount)) {
            cngRedPackedAmount = "0";
        }
        cngRedPackedAmount = ConverterHelper.toBigDecimal(cngRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        String sendRedPackedAmount = bean.getSendRedPackedAmount();
        if (StringUtils.isEmpty(sendRedPackedAmount)) {
            sendRedPackedAmount = "0";
        }
        sendRedPackedAmount = ConverterHelper.toBigDecimal(sendRedPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

        if (StringUtils.isEmpty(xcxAmount)) {
            // 小程序金额
            xcxAmount = "0";
        }
        double xcxAmountStr = ConverterHelper.toBigDecimal(xcxAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        if (StringUtils.isEmpty(posAmount)) {
            // 支付宝处理结果
            posAmount = "0";
        }
        double posAmountStr = ConverterHelper.toBigDecimal(posAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        if (StringUtils.isEmpty(memberCouponAmountSum)) {
            memberCouponAmountSum = "0";
        }
        double memberCouponAmountSumStr = ConverterHelper.toBigDecimal(memberCouponAmountSum).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        // 支付宝处理结果
        if (StringUtils.isEmpty(aliPayAmount)) {
            aliPayAmount = "0";
        }
        double aliPayAmountStr = ConverterHelper.toBigDecimal(aliPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();


        // 充值总额处理结果
        if (StringUtils.isEmpty(amount)) {
            amount = "0";
        }
        double amountStr = ConverterHelper.toBigDecimal(amount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //银联处理结果
        if (StringUtils.isEmpty(unionPayAmount)) {
            unionPayAmount = "0";
        }
        double unionPayAmountStr = ConverterHelper.toBigDecimal(unionPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //微信处理结果
        if (StringUtils.isEmpty(weixinPayAmount)) {
            weixinPayAmount = "0";
        }
        double weixinPayAmountStr = ConverterHelper.toBigDecimal(weixinPayAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        //余额处理结果
        if (StringUtils.isEmpty(cashAmount)) {
            cashAmount = "0";
        }
        String storeName = DataUtil.getInstance().getStoreName();
        String terminalName = DataUtil.getInstance().getTerminalName();
        double cashAmountStr = ConverterHelper.toBigDecimal(cashAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        String content = "交接班(车油服)\n" + "***********欢迎光临***********\n\n"
                + "门店名称：" + storeName + "\n"
                + "设备名称：" + terminalName + "\n"
                + "开始时间：" + startTime + "\n"
                + "结束时间：" + dataTime + "\n\n"
                + "充值总额：" + amountStr + "\n"
                + "支付宝：" + aliPayAmountStr + "\n"
                + "微信：" + weixinPayAmountStr + "\n"
                + "银联：" + unionPayAmountStr + "\n"
                + "现金：" + cashAmountStr + "\n"
                + "总订单数：" + orderCount + "\n"
                + "小程序总额：" + xcxAmountStr + "\n"
                + "pos总额：" + posAmountStr + "\n"
                + "红包总金额：" + redPackedAllAmount + "\n"
                + "汽油红包：" + qyRedPackedAmount + "\n"
                + "柴油红包：" + cyRedPackedAmount + "\n"
                + "LNG红包：" + lngRedPackedAmount + "\n"
                + "CNG红包：" + cngRedPackedAmount + "\n"
                + "补发红包：" + sendRedPackedAmount + "\n"
                + "------------------------------\n\n" +
                "本页由【车油服智慧有限公司】打印\n\n";
        SunmiPrintHelper.getInstance().printText(content, TextSize, isBold, false);
        SunmiPrintHelper.getInstance().feedPaper();
    }

    /**
     * 打印订单小票
     */
//    public void printOrderTicket(OrderListBean bean) {
//        String orderAmount = bean.getOrderAmount();
//        String payAmount = bean.getPayAmount();
//        String stationNameStr = bean.getStationName();
//        String time = String.valueOf(bean.getTime() == null ? "" : bean.getTime());
//        String oilNumStr = bean.getOilNum();
//        String orderNumber = bean.getOrderNumber();
//        String payType = bean.getPayType();
//        /**
//         * 会员id
//         * */
//        String memberId = bean.getMemberId();
//        /**
//         * 会员电话号
//         * */
//        String memberPhone = bean.getMemberPhone();
//        /**
//         * 设备来源
//         * */
//        String orderSource = bean.getOrderSource();
//        /**
//         * 优惠券个数
//         * */
//        int couponCount = bean.getCouponCount();
//
//        /**
//         * 会员余额
//         * */
//        String memberBlanceAmounts = bean.getRechargeBalance();
//        BigDecimal bigDecimalAmount = ConverterHelper.toBigDecimal(memberBlanceAmounts).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
//        double memberBlanceAmountsDou = bigDecimalAmount.doubleValue();
//        /**
//         * 赠送红包
//         * */
//        String redPackedAmount = bean.getRedPackedAmount();
//        double redPackedAmountDou = ConverterHelper.toBigDecimal(redPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//        String redPackedSum = bean.getRedPackedSum();
//        double redPackedSumDou = ConverterHelper.toBigDecimal(redPackedSum).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//
//        /**
//         * 剩余红包
//         * */
//        String memberRedPackedAmount = bean.getMemberRedPackedAmount();
//
//        /**
//         * 非油优惠券金额
//         * */
//        String goodsCouponAmount = bean.getGoodsCouponAmount();
//        double goodsCouponAmountDou = ConverterHelper.toBigDecimal(goodsCouponAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//        String payTypeStr = "";
//        if ("1".equals(payType)) {
//            payTypeStr = "支付宝支付";
//        } else if ("2".equals(payType)) {
//            payTypeStr = "微信支付";
//        } else if ("3".equals(payType)) {
//            payTypeStr = "银联支付";
//        } else if ("4".equals(payType)) {
//            payTypeStr = "余额支付";
//        } else if ("5".equals(payType)) {
//            payTypeStr = "现金支付";
//        }
//        double oilsPrices = 0, riseNew = 0;
//        //获取加油升数
//        try {
//            String oilPrice = bean.getOilPrice();
//            if (!StringUtils.isEmpty(oilPrice)) {
//                BigDecimal bigDecimal2 = ConverterHelper.toBigDecimal(oilPrice).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
//                oilsPrices = bigDecimal2.doubleValue();
//
//                BigDecimal bigDecimal = ConverterHelper.toBigDecimal(orderAmount).divide(ConverterHelper.toBigDecimal(oilsPrices), 2, BigDecimal.ROUND_HALF_UP);
//                riseNew = bigDecimal.doubleValue();
//            } else {
//                riseNew = 0;
//                oilsPrices = 0;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        double activityReductionDou = ConverterHelper.toBigDecimal(orderAmount).subtract(ConverterHelper.toBigDecimal(payAmount)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//
//        /**
//         * 是否显示加油升数
//         * */
//        String oilPriceSwitch = bean.getOilPriceSwitch();
//        if (StringUtils.isEmpty(oilPriceSwitch)) {
//            oilPriceSwitch = "1";
//        }
//
//
//        String timeout = bean.getTimeOutDate();
//        if (StringUtils.isEmpty(timeout)) {
//            timeout = "";
//        } else {
//            timeout = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(timeout) / 1000), "yyyy-MM-dd");
//        }
//
//        /**
//         * 车牌号和认证车辆
//         * */
//        String certificationTypeName = bean.getCertificationTypeName();
//        String carNumber = bean.getCarNumber();
//        Log.d("xxxxx订单类型", bean.getOrderType() + "+");
//        String reductionCouponAmount = bean.getReductionCouponAmount();
//        if ("2".equals(bean.getOrderType())) {
//
//            /**
//             * 判断是否是游客
//             * */
//            if ((!StringUtils.isEmpty(memberId) && "0".equals(memberId)) && (!StringUtils.isEmpty(orderSource) && "3".equals(orderSource))) {
//                PrintOrder(orderNumber, time, orderAmount, payAmount, oilNumStr, stationNameStr, payTypeStr, riseNew, oilsPrices, oilPriceSwitch, timeout, false);
//            }
//
//            /**
//             * 判断是一件加油
//             * */
//            if (!StringUtils.isEmpty(orderSource) && "1".equals(orderSource)) {
//                String title = "";
//                if (StringUtils.isEmpty(getuiOrderDTO.getPayRule())) {
//                    title = "消费凭证(一键加油)";
//                } else {
//                    if (getuiOrderDTO.getPayRule().equals("6"))
//                        title = "消费凭证(快速加油)";
//                }
//                getPrintOrder(title,orderAmount, payAmount, stationNameStr, activityReductionDou, oilNumStr,
//                        time, orderNumber, memberPhone, payTypeStr, riseNew, oilsPrices, oilPriceSwitch, certificationTypeName, carNumber, false);
//            }
//
//            /**
//             * 会员消费
//             * */
//            if ((!StringUtils.isEmpty(memberId) && !"0".equals(memberId)) && (!StringUtils.isEmpty(orderSource) && "3".equals(orderSource))) {
//                PrintMemberOrder(orderNumber, time, orderAmount, activityReductionDou + "", payAmount, oilNumStr, stationNameStr, payTypeStr, memberBlanceAmountsDou + "", payType, couponCount + "", riseNew + "", oilsPrices + "", oilPriceSwitch, memberRedPackedAmount, false, bean.getMemberInfoCardDTO(), bean.getOilNum(), bean.getMemberPhone(), bean.getRedPackedAmount(), bean.getStoreDownAmount());
//            }
//
//        } else if ("3".equals(bean.getOrderType())) {
//            /**
//             * 充值打印小票
//             * */
//            PrintRechargeOrder(orderNumber, time, orderAmount, stationNameStr, payTypeStr, memberBlanceAmountsDou, memberPhone, redPackedAmountDou, goodsCouponAmountDou, redPackedSumDou, "", reductionCouponAmount, false);
//        }
//    }

    /**
     * 游客 收款功能小票
     */
    public void PrintOrder(String orderNumber, String time, String orderAmountStr,
                           String payAmountStr, String oilNumStr,
                           String stationNameStr, String payTypeStr, double riseNew, double oilsPrices,
                           String oilPriceSwitch, String timeouts, boolean isShow) {
        boolean isPrintQR;
        String strr = "";
        if (isShow) {
            strr = "(重打印)";
        } else {
            if (!SPUtil.getInstance().getString(ConfigureFile.OTHERTICKET, "").equals("1")) {
                return;
            }
        }

        StringBuilder strB1 = new StringBuilder();
        strB1.append("消费凭证").append(strr).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);

        StringBuilder strB2 = new StringBuilder();
        strB2.append("实付金额：").append(payAmountStr).append("\n").append("支付方式：").append(payTypeStr).append("\n");

        if ("1".equals(oilPriceSwitch) && oilsPrices > 0) {
            strB2.append("加油升数：").append(riseNew).append("L").append("\n").append("平台价格：").append(oilsPrices).append("\n");
        }
        strB2.append("油品油号：").append(oilNumStr).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB2.toString(), 26, false, 1, false);

        StringBuilder strB3 = new StringBuilder();
        strB3.append("订单金额\n").append("¥").append(orderAmountStr);
        SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, false, 1, false);

        StringBuilder strB4 = new StringBuilder();
        strB4.append("-------------------------\n").append("门店名称：").append(stationNameStr).append("\n").append("订单编号：").append(orderNumber).append("\n")
                .append("支付时间：").append(time).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);

        StringBuilder strB6 = new StringBuilder();
        strB6.append("本小票仅作为参考凭证\n\n\n");//.append("注：优惠金额不参与开具发票\n\n\n")
        SunmiPrintHelper.getInstance().printOneOilText(strB6.toString(), 26, true, 2, false);

        if ("1".equals(DataUtil.getInstance().getQrSwitch())) {
            isPrintQR = true;
        } else {
            isPrintQR = false;
        }
        if (isPrintQR) {
            SunmiPrintHelper.getInstance().printQr(orderNumber, 8, 2);
        }
        SunmiPrintHelper.getInstance().feedPaper();
    }

    /**
     * 打印一键加油小票样式
     */
    public void getPrintOrder(String title, String orderAmount, String payAmount, String stationNameStr, double activityReductionDou, String oilNumStr,
                              String time, String orderNumber, String memberPhone, String payTypeStr, double riseNew, double oilsPrices,
                              String oilPriceSwitch, String certificationTypeName, String carNumber, boolean isShow) {
        String strr = "";
        if (isShow) {
            strr = "(重打印)";
        } else {
            if (!SPUtil.getInstance().getString(ConfigureFile.OTHERTICKET, "").equals("1")) {
                return;
            }
        }

//        if (DataUtil.getInstance().getPrintPosition().equals("1"))//使用模板1打印小票
//        {
//            StringBuilder strB1 = new StringBuilder();
//            strB1.append(title).append(strr).append("\n").append("-------------------------");
//            SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);
//
//
//            StringBuilder strB2 = new StringBuilder();
//            strB2.append("时间：").append(time);
//            SunmiPrintHelper.getInstance().printOneOilText(strB2.toString(), 28, true, 1, false);
//
//
//            StringBuilder strB3 = new StringBuilder();
//            strB3.append("金额：").append(orderAmount);
//            SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, true, 1, false);
//
//
//            StringBuilder strB4 = new StringBuilder();
//            strB4.append("-------------------------\n").append("优惠金额：").append(activityReductionDou).append("\n")
//                    .append("实付金额：").append(payAmount).append("\n")
//                    .append("支付方式：").append(payTypeStr).append("\n")
//                    .append("油品油号：").append(oilNumStr).append("\n");
//            if ("1".equals(oilPriceSwitch) && oilsPrices > 0) {
//                strB4.append("加油升数：").append(riseNew).append("L\n").append("平台价格：").append(oilsPrices).append("\n");
//            }
//            if (!StringUtils.isEmpty(memberPhone)) {
//                strB4.append("手机号码：").append(memberPhone.substring(0, 3)).append("****").append(memberPhone.substring(7, memberPhone.length())).append("\n");
//            }
//            if (!StringUtils.isEmpty(certificationTypeName)) {
//                strB4.append("认证类型：").append(certificationTypeName).append("\n");
//            }
//            if (!StringUtils.isEmpty(carNumber)) {
//                strB4.append("车牌号码：").append(carNumber).append("\n");
//            }
//            strB4.append("-------------------------\n").append("门店名称：").append(stationNameStr).append("\n").append("订单编号：").append(orderNumber).append("\n").append("-------------------------");
//            SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);
//
//            StringBuilder strB5 = new StringBuilder();
//            strB5.append("本小票仅作为参考凭证\n").append("\n\n\n");//.append("注：优惠金额不参与开具发票\n\n\n")
//            SunmiPrintHelper.getInstance().printOneOilText(strB5.toString(), 26, true, 2, false);
//        } else //使用模板2打印小票
//        {
        StringBuilder strB1 = new StringBuilder();
        strB1.append(title).append(strr).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);

        StringBuilder strB4 = new StringBuilder();
        strB4.append("优惠金额：").append(activityReductionDou).append("\n")
                .append("实付金额：").append(payAmount).append("\n")
                .append("支付方式：").append(payTypeStr).append("\n")
                .append("油品油号：").append(oilNumStr).append("\n");
        if ("1".equals(oilPriceSwitch) && oilsPrices > 0) {
            strB4.append("加油升数：").append(riseNew).append("L\n").append("平台价格：").append(oilsPrices).append("\n");
        }
        if (!StringUtils.isEmpty(memberPhone)) {
            strB4.append("手机号码：").append(memberPhone.substring(0, 3)).append("****").append(memberPhone.substring(7, memberPhone.length())).append("\n");
        }
        if (!StringUtils.isEmpty(certificationTypeName)) {
            strB4.append("认证类型：").append(certificationTypeName).append("\n");
        }
        if (!StringUtils.isEmpty(carNumber)) {
            strB4.append("车牌号码：").append(carNumber).append("\n");
        }
        strB4.append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);

        StringBuilder strB3 = new StringBuilder();
        strB3.append("订单金额\n").append("¥").append(orderAmount);
        SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, false, 1, false);

        StringBuilder strB5 = new StringBuilder();
        strB5.append("-------------------------\n").append("门店名称：").append(stationNameStr).append("\n").append("订单编号：").append(orderNumber).append("\n").append("支付时间：").append(time).append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB5.toString(), 26, false, 1, false);

        StringBuilder strB6 = new StringBuilder();
        strB6.append("本小票仅作为参考凭证\n").append("\n\n\n");//.append("注：优惠金额不参与开具发票\n\n\n")
        SunmiPrintHelper.getInstance().printOneOilText(strB6.toString(), 26, true, 2, false);
        //  }


    }

    /**
     * 会员消费小票样式
     *
     * @param orderNumber
     * @param time
     * @param orderAmount
     * @param activityReductionDou
     * @param payAmount
     * @param oilNumStr
     * @param stationNameStr
     * @param payTypeStr
     * @param memberBlanceAmountsDou
     * @param payType
     * @param couponCount
     * @param riseNew
     * @param oilsPrices
     * @param oilPriceSwitch
     * @param memberRedPackedAmount
     * @param isReprint              是否重打印
     * @param memberInfoCardDTO
     * @param oilNum
     */
    public void PrintMemberOrder(String orderNumber, String time, String orderAmount, String activityReductionDou, String payAmount, String oilNumStr, String stationNameStr, String payTypeStr, String memberBlanceAmountsDou, String payType, String couponCount, String riseNew,
                                 String oilsPrices, String oilPriceSwitch, String memberRedPackedAmount, boolean isReprint, OrderDetialBean.MemberInfoCardDTO memberInfoCardDTO, String oilNum, String Phone, String redPackedAmount, String storeDownAmount) {
        String strr = "";
        String content;
        boolean isPrintGZH = true;
        String mainPhone = memberInfoCardDTO.getMainPhone();
        if (mainPhone == null) {
            mainPhone = Phone;
        }
        if (!StringUtils.isEmpty(mainPhone) && mainPhone.length() >= 11) {
            mainPhone = mainPhone.substring(0, 3) + "****" + mainPhone.substring(7, mainPhone.length());
        }
        if (isReprint) {
            strr = "(重打印)";
            isPrintGZH = false;
        } else {
            isPrintGZH = DataUtil.getInstance().getGzhSwith().equals("1") ? true : false;
            if (!SPUtil.getInstance().getString(ConfigureFile.OTHERTICKET, "").equals("1")) {
                return;
            }
        }
        if (memberInfoCardDTO != null && !StringUtils.isEmpty(memberInfoCardDTO.getParentId()) && !memberInfoCardDTO.getParentId().equals("0"))//副卡消费
        {
            String rechargeBalance = memberInfoCardDTO.getRechargeBalance();
            if (StringUtils.isEmpty(rechargeBalance)) {
                rechargeBalance = "0";
            } else {
                BigDecimal bigDecimalAmount = ConverterHelper.toBigDecimal(rechargeBalance).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
                rechargeBalance = bigDecimalAmount.doubleValue() + "";
            }

            StringBuilder strB1 = new StringBuilder();
            strB1.append("会员消费凭证").append(strr).append("\n").append("-------------------------");
            SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);

            StringBuilder strB2 = new StringBuilder();
            strB2.append("实付金额：").append(payAmount).append("\n").append("支付方式：").append(payTypeStr).append("\n");


//            content = "会员消费凭证" + strr + "\n" + "***********欢迎光临***********\n\n"
//                    + "订单金额：" + orderAmount + "\n"
//                    + "实付金额：" + payAmount + "\n"
//                    + "支付方式：" + payTypeStr + "\n";
            if ("1".equals(oilPriceSwitch) && Double.valueOf(oilsPrices) > 0) {
//                content = content + "加油升数：" + riseNew + "L" + "\n"
//                        + "会员价：" + oilsPrices + "\n";
                strB2.append("加油升数：").append(riseNew).append("L").append("\n").append("平台价格：").append(oilsPrices).append("\n");
            }
            strB2.append("油品油号：").append(oilNum).append("\n").append("剩余额度：").append(rechargeBalance).append("\n").append("主卡手机号：").append(mainPhone).append("\n")
                    .append("-------------------------");
//            content = content + "油号：" + oilNum + "\n"
//                    + "主卡手机号：" + mainPhone + "\n"
//                    + "剩余额度：" + rechargeBalance + "\n"
//                    + "注：剩余额度仅供参考，实际消费以主卡为准\n";

            SunmiPrintHelper.getInstance().printOneOilText(strB2.toString(), 26, false, 1, false);


            StringBuilder strB3 = new StringBuilder();
            strB3.append("订单金额\n").append("¥").append(orderAmount);
            SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, false, 1, false);


            StringBuilder strB4 = new StringBuilder();
            strB4.append("-------------------------\n").append("门店名称：").append(stationNameStr).append("\n").append("订单编号：").append(orderNumber)
                    .append("\n").append("支付时间：").append(time).append("\n").append("-------------------------");
            SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);

            StringBuilder strB5 = new StringBuilder();
            strB5.append("注：剩余额度仅供参考，实际消费以主卡为准\n").append("本小票仅作为参考凭证\n\n\n\n");
            SunmiPrintHelper.getInstance().printOneOilText(strB5.toString(), 26, true, 1, false);
//            content = content
//                    + "------------------------------\n"
//                    + "门店名称：" + stationNameStr + "\n"
//                    + "订单号：" + orderNumber + "\n"
//                    + "" + time + "\n"
//                    + "本小票仅作为参考凭证\n\n\n";
            // printTextContent(content);

        } else//主卡消费
        {
            String couponStr;
            if (Integer.valueOf(couponCount == null ? "0" : couponCount) > 1) {
                couponStr = "(使用了" + couponCount + "张优惠券)";
            } else {
                couponStr = "";
            }
            redPackedAmount = ConverterHelper.toBigDecimal(redPackedAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP) + "";
            String ZHAmount = ConverterHelper.toBigDecimal(memberRedPackedAmount).add(ConverterHelper.toBigDecimal(memberBlanceAmountsDou)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            storeDownAmount = ConverterHelper.toBigDecimal(activityReductionDou).subtract(ConverterHelper.toBigDecimal(redPackedAmount)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();

            StringBuilder strB1 = new StringBuilder();
            strB1.append("会员消费凭证").append(strr).append("\n").append("-------------------------");
            SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);

            StringBuilder strB2 = new StringBuilder();
            strB2.append("实付金额：").append(payAmount).append("\n").append("红包抵扣：").append(redPackedAmount).append("\n").append("门店优惠：").append(storeDownAmount).append(couponStr).append("\n").append("支付方式：").append(payTypeStr).append("\n");

//            String content1 = "会员消费凭证" + strr + "\n" + "------------------------------\n"
//                    + "订单金额：" + orderAmount + "\n"
//                    // + "优惠金额：" + activityReductionDou + couponStr + "\n"
//                    + "红包抵扣：" + redPackedAmount + "\n"
//                    + "门店优惠：" + storeDownAmount + couponStr + "\n"
//                    + "支付方式：" + payTypeStr + "\n";
            if ("1".equals(oilPriceSwitch) && Double.valueOf(riseNew == null ? "0" : riseNew) > 0) {
//                content1 = content1 + "加油升数：" + riseNew + "L" + "\n"
//                        + "会员价格：" + oilsPrices + "\n";
                strB2.append("加油升数：").append(riseNew).append("L").append("\n").append("会员价格：").append(oilsPrices).append("\n");
            }
            strB2.append("油品油号：").append(oilNumStr).append("\n").append("手机号码：").append(mainPhone).append("\n").append("卡片余额：").append(memberBlanceAmountsDou)
                    .append("\n").append("红包余额：").append(memberRedPackedAmount).append("\n").append("账户总额：").append(ZHAmount).append("\n").append("-------------------------");
            SunmiPrintHelper.getInstance().printOneOilText(strB2.toString(), 26, false, 1, false);
//            content1 = content1 + "油品油号：" + oilNumStr + "\n"
//                    + "手机号码：" + mainPhone + "\n"
//                    + "卡片余额：" + memberBlanceAmountsDou + "\n"
//                    + "红包余额：" + memberRedPackedAmount + "\n"
//                    + "账户总额：" + ZHAmount;
//            String content2 = "实付金额：" + payAmount;

            StringBuilder strB3 = new StringBuilder();
            strB3.append("订单金额\n").append("¥").append(orderAmount);
            SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, false, 1, false);

            StringBuilder strB4 = new StringBuilder();
            strB4.append("-------------------------\n").append("门店名称：").append(stationNameStr).append("\n").append("订单编号：").append(orderNumber).append("\n")
                    .append("支付时间：").append(time).append("\n").append("-------------------------");
            SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);
//            String content3 = "------------------------------\n"
//                    + "门店名称：" + stationNameStr + "\n"
//                    + "订单编号：" + orderNumber + "\n"
//                    + "" + time + "\n"
//                    + "本小票仅作为参考凭证\n\n\n\n";
//            SunmiPrintHelper.getInstance().printOneOilText(content1, 24, true, 1, false);
//            SunmiPrintHelper.getInstance().printOneOilText(content2, 36, true, 1, false);
//            SunmiPrintHelper.getInstance().printOneOilText(content3, 24, true, 1, false);
            StringBuilder strB6 = new StringBuilder();
            strB6.append("本小票仅作为参考凭证\n").append("\n\n\n");//.append("注：优惠金额不参与开具发票\n\n\n")
            SunmiPrintHelper.getInstance().printOneOilText(strB6.toString(), 26, true, 2, false);
        }


        printQr(orderNumber, false, isPrintGZH);
    }

    /**
     * 充值打印小票
     */
    public void PrintRechargeOrder(String orderNumber, String time, String orderAmountStr, String stationNameStr, String payTypeStr, double memberBlanceAmountsDou, String memberPhone, double redPackedAmountDou, double goodsCouponAmountDou, double redPackedSumDou, String oilType, String reductionCouponAmount, boolean isReprint) {
        String strr = "";
        boolean isPrintGZH;
        if (isReprint) {
            strr = "(重打印)";
            isPrintGZH = false;
        } else {
            isPrintGZH = DataUtil.getInstance().getGzhSwith().equals("1") ? true : false;
            if (!SPUtil.getInstance().getString(ConfigureFile.OTHERTICKET, "").equals("1")) {
                return;
            }
        }
        String ZHAmount = ConverterHelper.toBigDecimal(redPackedSumDou).add(ConverterHelper.toBigDecimal(memberBlanceAmountsDou)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();

        if (StringUtils.isEmpty(reductionCouponAmount)) {
            reductionCouponAmount = "0";
        } else {
            reductionCouponAmount = ConverterHelper.toBigDecimal(reductionCouponAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
        }

        StringBuilder strB1 = new StringBuilder();
        strB1.append("会员充值凭证").append(strr).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);

        StringBuilder strB2 = new StringBuilder();
        strB2.append("赠送优惠券金额：").append(reductionCouponAmount).append("\n").append("赠送非油券金额：").append(goodsCouponAmountDou).append("\n")
        .append("赠送红包：").append(redPackedAmountDou).append("\n").append("油品类型：").append(oilType)
                .append("\n").append("支付方式：").append(payTypeStr).append("\n").append("卡片余额：").append(memberBlanceAmountsDou).append("\n").append("账户总额：").append(ZHAmount).append("\n");


//        String content = "会员充值凭证" + strr + "\n" + "***********欢迎光临***********\n"
//                + "赠送红包：" + redPackedAmountDou + "\n"
//                + "赠送非油券金额：" + goodsCouponAmountDou + "\n"
//                + "赠送优惠券金额：" + reductionCouponAmount + "\n"
//                + "充值金额：" + orderAmountStr + "\n"
//                + "油品类型：" + oilType + "\n"
//                + "支付方式：" + payTypeStr + "\n"
//                + "卡余额：" + memberBlanceAmountsDou + "\n"
//                + "账户余额：" + ZHAmount + "\n";
        if (!StringUtils.isEmpty(memberPhone)) {
            //content = content + "会员：" + memberPhone.substring(0, 3) + "****" + memberPhone.substring(7, memberPhone.length()) + "\n\n";
            strB2.append( "会员手机：").append(memberPhone.substring(0, 3)).append("****").append(memberPhone.substring(7, memberPhone.length())).append( "\n");
        }
        strB2.append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB2.toString(), 26, false, 1, false);

        StringBuilder strB3 = new StringBuilder();
        strB3.append("充值金额\n").append("¥").append(orderAmountStr);
        SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, false, 1, false);

        StringBuilder strB4 = new StringBuilder();
        strB4.append("-------------------------\n").append("门店名称：").append(stationNameStr).append("\n").append("订单编号：").append(orderNumber).append("\n")
                .append("充值时间：").append(time).append("\n").append("-------------------------\n");
        SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);

//        content = content + "------------------------------\n"
//                + "站点名称：" + stationNameStr + "\n"
//                + "订单号：" + orderNumber + "\n"
//                + "" + time + "\n"
//                + "本小票仅作为参考凭证\n\n\n";
//        printTextContent(content);
        StringBuilder strB6 = new StringBuilder();
        strB6.append("本小票仅作为参考凭证\n").append("\n\n\n");//.append("注：优惠金额不参与开具发票\n\n\n")
        SunmiPrintHelper.getInstance().printOneOilText(strB6.toString(), 26, true, 2, false);
        printQr(orderNumber, false, isPrintGZH);
    }

    /**
     * 打印操作员收费小票
     *
     * @param bean
     */
    public void PrintOperatorChargeTicket(OrderDetialBean bean, boolean isReprint) {
        String strr = "";
        boolean isPrintGZH;
        if (isReprint) {
            strr = "(重打印)";
            isPrintGZH = false;
        } else {
            isPrintGZH = DataUtil.getInstance().getGzhSwith().equals("1") ? true : false;
            if (!SPUtil.getInstance().getString(ConfigureFile.OTHERTICKET, "").equals("1")) {
                return;
            }
        }
        String orderNum = bean.getOrderNumber();
        String orderCreateTime = String.valueOf(bean.getOrderCreateTime());
        String createTime = "";
        if (!StringUtils.isEmpty(orderCreateTime)) {
            createTime = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(orderCreateTime) / 1000), "yyyy-MM-dd HH:mm:ss");
        }

        String timeout = bean.getTimeOutDate();
        if (StringUtils.isEmpty(timeout)) {
            timeout = "";
        } else {
            timeout = FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(timeout) / 1000), "yyyy-MM-dd");
        }
        int orderAmount = bean.getOrderAmount();
        int payAmount = bean.getPayAmount();
        String oilNum = bean.getOilNum();
        String storeName = bean.getStoreName();
        String payType = bean.getPayType();
        String payTypeStr = "";
        if (!StringUtils.isEmpty(payType)) {
            if ("1".equals(payType)) {
                payTypeStr = "支付宝支付";
            } else if ("2".equals(payType)) {
                payTypeStr = "微信支付";
            } else if ("3".equals(payType)) {
                payTypeStr = "银联支付";
            } else if ("4".equals(payType)) {
                payTypeStr = "会员支付";
            }
        }
        double oilsPrices = 0.00;
        try {
            String oilPrice = bean.getOilPrice();
            if (!StringUtils.isEmpty(oilPrice)) {
                oilsPrices = ConverterHelper.toBigDecimal(oilPrice).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            } else {
                oilsPrices = 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            oilsPrices = 0;
        }
        String rise = "";
        try {
            rise = bean.getRise();

            if (StringUtils.isEmpty(rise)) {
                rise = "0";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        String oilPriceSwitch = bean.getOilPriceSwitch();
        if (StringUtils.isEmpty(oilPriceSwitch)) {
            oilPriceSwitch = "1";
        }

        double orderAmountDou = ConverterHelper.toBigDecimal(orderAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        double shiAmount = ConverterHelper.toBigDecimal(payAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        boolean isPrintQR;
        String content;
        if ("1".equals(DataUtil.getInstance().getQrSwitch())) {
            isPrintQR = true;


//            content = content + "油号：" + oilNum + "\n"
//                    + "------------------------------\n"
//                    + "门店名称：" + storeName + "\n"
//                    + "订单号：" + orderNum + "\n"
//                    + "" + createTime + "\n"
//                    + "本小票仅作为参考凭证\n\n"
//                    // + "注：请保留好此小票，凭小票兑换发票(有效期:" + timeout + ")\n"
//                    + "------------------------------\n\n";
            //"             发票码";
        } else {
            isPrintQR = false;

//            content = "消费凭证" + strr + "\n" + "***********欢迎光临***********\n\n"
//                    + "订单金额：" + orderAmountDou + "\n"
//                    + "实付金额：" + shiAmount + "\n"
//                    + "支付方式：" + payTypeStr + "\n";
//            if ("1".equals(oilPriceSwitch) && oilsPrices > 0) {
//                content = content + "加油升数：" + rise + "L" + "\n"
//                        + "油价：" + oilsPrices + "\n";
//            }
//            content = content + "油号：" + oilNum + "\n"
//                    + "------------------------------\n"
//                    + "门店名称：" + storeName + "\n"
//                    + "订单号：" + orderNum + "\n"
//                    + "" + createTime + "\n"
//                    + "本小票仅作为参考凭证\n\n\n";
        }
        StringBuilder strB1 = new StringBuilder();
        strB1.append("消费凭证").append(strr).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB1.toString(), 26, true, 1, false);

        StringBuilder strB2 = new StringBuilder();
        strB2.append("实付金额：").append(shiAmount).append("\n").append("支付方式：").append(payTypeStr).append("\n");

        //            content = "消费凭证" + strr + "\n" + "***********欢迎光临***********\n\n"
//                    + "订单金额：" + orderAmountDou + "\n"
//                    + "实付金额：" + shiAmount + "\n"
//                    + "支付方式：" + payTypeStr + "\n";
        if ("1".equals(oilPriceSwitch) && oilsPrices > 0) {
//                content = content + "加油升数：" + rise + "L" + "\n"
//                        + "油价：" + oilsPrices + "\n";
            strB2.append("加油升数：").append(rise).append("L").append("\n").append("平台价格：").append(oilsPrices).append("\n");
        }
        strB2.append("油品油号：").append(oilNum).append("\n").append("-------------------------");
        SunmiPrintHelper.getInstance().printOneOilText(strB2.toString(), 26, false, 1, false);


        StringBuilder strB3 = new StringBuilder();
        strB3.append("订单金额\n").append("¥").append(orderAmountDou);
        SunmiPrintHelper.getInstance().printOneOilText(strB3.toString(), 46, false, 1, false);

        StringBuilder strB4 = new StringBuilder();
        strB4.append("-------------------------\n").append("门店名称：").append(storeName).append("\n").append("订单编号：").append(orderNum).append("\n")
                .append("支付时间：").append(createTime).append("\n").append("-------------------------\n");
        SunmiPrintHelper.getInstance().printOneOilText(strB4.toString(), 26, false, 1, false);

        StringBuilder strB5 = new StringBuilder();
        strB5.append("本小票仅作为参考凭证\n").append("\n\n\n");//.append("注：优惠金额不参与开具发票\n\n\n")
        SunmiPrintHelper.getInstance().printOneOilText(strB5.toString(), 26, true, 2, false);

        //PrintContent(content, orderNum, isPrintQR);
        // printTextContent(content);
        printQr(orderNum, isPrintQR, isPrintGZH);
    }

    /**
     * 打印
     *
     * @param content   打印文本
     * @param orderNum  订单号
     * @param isPrintQR 是否打印二维码
     */
    private void PrintContent(String content, String orderNum, boolean isPrintQR) {
        SunmiPrintHelper.getInstance().printText(content, TextSize, isBold, false);
        if (isPrintQR) {
            SunmiPrintHelper.getInstance().printQr(orderNum, 8, 2);
        }
        SunmiPrintHelper.getInstance().feedPaper();
    }

    /**
     * 创建洗车卡小票
     */
    public void printBarCodeContent(CarCardBean bean, String cardName) {
        String carCardId = bean.getId();
        if (StringUtils.isEmpty(carCardId)) {
            carCardId = "";
        }
        String limitTime = bean.getTimeOut();
        String time = "";
        if (!StringUtils.isEmpty(limitTime)) {
            time = limitTime.substring(0, 10);
        }

        String storeName = bean.getStoreName();
        if (StringUtils.isEmpty(storeName)) {
            storeName = "";
        }
        String contactsPhone = bean.getContactsPhone();
        if (StringUtils.isEmpty(contactsPhone)) {
            contactsPhone = "";
        }

        String content1 = "\t\t\t\t\t\t\t\t\t\t\t\t条形码仅供核销使用" +
                "\n油站门店：" + storeName + "\n"
                + "油站电话：" + contactsPhone + "\n"
                + "有效期至：" + time + "\n\n"

                + "注：此码扫码一次后即作废，请勿泄露给他人\n\n\n";

        String content2 = cardName + "凭证\n" + "***********欢迎光临***********";

        DecimalFormat df = new DecimalFormat("0000000");
        String str2 = df.format(Integer.parseInt(carCardId));
        SunmiPrintHelper.getInstance().printText(content2, TextSize, isBold, false);
        SunmiPrintHelper.getInstance().printBarCode(str2, 8, 120, 3, 0);
        SunmiPrintHelper.getInstance().printText(content1, TextSize, isBold, false);
    }

    /**
     * 设置打印的公众号图片大小
     *
     * @param bitmap
     * @return
     */
    public Bitmap changeBitmapSize(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        //设置想要的大小
        int newWidth = 200;
        int newHeight = 200;

        //计算压缩的比率
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;

        //获取想要缩放的matrix
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);

        //获取新的bitmap
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        bitmap.getWidth();
        bitmap.getHeight();
        return bitmap;
    }

    /**
     * 打印文本
     *
     * @param content
     */
    private void printTextContent(String content) {
        SunmiPrintHelper.getInstance().printText(content, TextSize, isBold, false);
    }

    /**
     * 是否打印二维码和公众号的二维码
     *
     * @param orderNum
     * @param isQr
     * @param isPrintGZH
     */
    private void printQr(String orderNum, boolean isQr, boolean isPrintGZH) {
        if (isQr) {
            SunmiPrintHelper.getInstance().getInstance().printQr(orderNum, 8, 2);
            SunmiPrintHelper.getInstance().feedPaper();
        }

        if (isPrintGZH) {
            Bitmap bitmap = BitmapFactory.decodeResource(BaseApplation.instance().getResources(), R.mipmap.gongzhonghao, null);
            if (bitmap != null) {
                Bitmap bitmapMin = changeBitmapSize(bitmap);
                SunmiPrintHelper.getInstance().printTextCenter("关注公众号\n加油更优惠", 50, true, false);
                SunmiPrintHelper.getInstance().printBitmap(bitmapMin);
                SunmiPrintHelper.getInstance().printText("\n\n", 24, true, false);
            }
        }
    }

}


